// const { data } = require('jquery')
const db = require('./db')

// 注册
const register = (req, res) => {
    let sql = `INSERT INTO users (userName, passWord) VALUES (?,?);`
    return new Promise((resolve, reject) => {
        db.query(sql, [req.body.name, req.body.pwd], (err, data) => {
            if (err) {
                reject(err)
            } else {
                resolve(data)
            }
        })
    })
}

//登录
const login = (req, res) => {
    let sql = `SELECT userName,passWord FROM users WHERE userName=?&&passWord=?;`
    return new Promise((resolve, reject) => {
        db.query(sql, [req.body.name, req.body.pwd], (err, data) => {
            if (err) {
                reject(err)
            } else {
                resolve(data)
            }
        })
    })
}

module.exports = {
    register,
    login
}